import uuid

from django.db import models
from post.models import PostList
from music.models import MusicList
# Create your models here.

class MusicComment(models.Model):
    id = models.CharField(max_length=128, primary_key=True, verbose_name='Id')
    user = models.ForeignKey('user.User', db_column='user', on_delete=models.CASCADE, verbose_name='评论用户')
    music = models.ForeignKey('music.MusicList', db_column='music', on_delete=models.CASCADE, verbose_name='评论音乐')
    content = models.TextField(verbose_name='评论内容')
    collect_time = models.DateTimeField(auto_now_add=True, verbose_name='评论时间')

    class Meta():
        verbose_name = '音乐评论'
        verbose_name_plural = verbose_name
        db_table = 'music_comment'
        managed = True

    def save(self, *args, **kwargs):
        if not self.id:
            self.id = uuid.uuid4()
        super(MusicComment, self).save()


class PostComment(models.Model):
    id = models.CharField(max_length=128, primary_key=True, verbose_name='Id')
    user = models.ForeignKey('user.User', db_column='user', on_delete=models.CASCADE, verbose_name='评论用户')
    post = models.ForeignKey('post.PostList', db_column='post', on_delete=models.CASCADE, verbose_name='评论主题')
    content = models.TextField(verbose_name='评论内容')
    collect_time = models.DateTimeField(auto_now_add=True, verbose_name='评论时间')

    class Meta():
        verbose_name = '主题帖评论'
        verbose_name_plural = verbose_name
        db_table = 'post_comment'
        managed = True

    # def __str__(self):
    #     post_name = PostList.objects.filter(self.post_id)
    #     return post_name

    def save(self, *args, **kwargs):
        if not self.id:
            self.id = uuid.uuid4()
        super(PostComment, self).save()